cellRank builds a graph based on a transition matrix. The transition matrix contains the probabilities of cell–>cell transitions, which are calculated as a weighted average between (similarity of velocity vector and cell difference vector) and (euclidean similarity in PCA space). Here, we want to compare this graph to the graph that we build using projectedNeighbors.
Use the reticulate package to use scVelo/cellrank from within R:
Build graph with all data i.e. with cells from all parts of the trajectory.
load complete adata from previous run
load pancreas data
Run scVelo
Run velocity
Run cellrank
Save adata to speed up later
Extract transition matrices
## <Conn[dnorm=True]>
## <Velo[softmax_scale=3.8, mode=deterministic, seed=3185]>
Weighted graphs from transition matrices
adjacency = transition matrix –> fdg
Distances: transition matrix using just euclidean similarity
Velocities: transition matrix using just velocity correlation
Combined: transition matrix = weighted average of distance and velocity
(using default weight 0.8velocity + 0.2distance)
Varying weight in weighted average
Build graph with data where part of the trajectory is missing.
load missing intermediate adata from previous run
load pancreas data
Run scVelo
Run velocity
Run cellrank
Save adata to speed up later
Extract transition matrices
## <Conn[dnorm=True]>
## <Velo[softmax_scale=3.86, mode=deterministic, seed=65033]>
Weighted graphs from transition matrices
adjacency = transition matrix –> fdg
Distances: transition matrix using just euclidean similarity
Velocities: transition matrix using just velocity correlation
Combined: transition matrix = weighted average of distance and velocity
(using default weight 0.8velocity + 0.2distance)
Varying weight in weighted average
Extract count data..
Filter genes
(Downsample cells to make things easier)
Normalize for dimensional reduction
## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...
Dimensional reduction
Run velocyto on panc data
## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...
Scores of observed and projected states in PC space
Graph visualization on subset of cells from PC coordinates
Extract count data..
Filter genes
(Downsample cells to make things easier)
Normalize for dimensional reduction
## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...
Dimensional reduction
Run velocyto on panc data
## Warning in if (!class(counts) %in% c("dgCMatrix", "dgTMatrix")) {: the condition
## has length > 1 and only the first element will be used
## Converting to sparse matrix ...
Scores of observed and projected states in PC space
Graph visualization on subset of cells from PC coordinates
Above, I used k=30 for direct comparison to cellRank graph which computes distances to K=30 nearest neighbors uses. However, this might not be where veloviz performs best.
Compare mean distance between cells before and after the gap normalized by max distance between any two cells for each graph.
Comparing default cellRank graph to veloViz graph
Comparing ‘best’ cellRank graph (only velocity based) to ‘best’ veloViz graph (k = 10)